import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index.js'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 添加暗黑模式样式
import 'element-plus/theme-chalk/dark/css-vars.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// 修复导入顺序 - 提前导入ConfigProvider
import { ElConfigProvider as ConfigProvider } from 'element-plus';
// 导入主题工具
import { initTheme } from './utils/theme'
// 导入主题变量
import './styles/variables.scss'

// 初始化主题
initTheme();

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(ElementPlus, { locale: zhCn })
  .component('ConfigProvider', ConfigProvider)

// 在挂载前设置主题模式
const theme = localStorage.getItem('app-theme') || 'light';
document.documentElement.setAttribute('class', theme);

app.use(router)
app.mount('#app')